package com.lemner.ke.util;

import android.app.Activity;
import android.content.Context;
import android.os.Environment;

import com.laojiang.imagepickers.ImagePicker;
import com.laojiang.imagepickers.data.ImagePickType;
import com.laojiang.imagepickers.utils.GlideImagePickerDisplayer;

/**
 * 照片选择器仿照微信，适配安卓7.0
 *
 * @author 杨烨
 * @date 2018/9/10
 */
public class MyImagePicker {
    private final String CACEH_PATH = Environment.getExternalStorageDirectory() + "/Ke/Cache";
    public static final int REQUEST_CODE = 101, RESULT_CODE = 202;
    public ImagePicker build;

    public MyImagePicker(Context context, ImagePickType mode, Boolean setCrop) {
        if (setCrop) {
            build = new ImagePicker.Builder()
                    .pickType(mode) //设置选取类型(拍照ONLY_CAMERA、单选SINGLE、多选MUTIL)
                    .needCamera(false) //是否需要在界面中显示相机入口(类似微信那样)
                    .doCrop(1, 1, 300, 300)
                    .cachePath(CACEH_PATH) //自定义缓存路径(拍照和裁剪都需要用到缓存)
                    .needVideo(true)//是否显示视频 设置
                    .displayer(new GlideImagePickerDisplayer()) //自定义图片加载器，默认是Glide实现的,可自定义图片加载器
                    .build();
        } else {
            build = new ImagePicker.Builder()
                    .pickType(mode) //设置选取类型(拍照ONLY_CAMERA、单选SINGLE、多选MUTIL)
                    .needCamera(false) //是否需要在界面中显示相机入口(类似微信那样)
                    .cachePath(CACEH_PATH) //自定义缓存路径(拍照和裁剪都需要用到缓存)
                    .needVideo(false)//是否显示视频 设置
                    .displayer(new GlideImagePickerDisplayer()) //自定义图片加载器，默认是Glide实现的,可自定义图片加载器
                    .build();
        }
        build.start((Activity) context, REQUEST_CODE, RESULT_CODE);
    }
}
